package sss;

import java.util.HashMap;
import java.util.Scanner;

/**
 * @author VernHe
 * @date 2021年08月13日 16:54
 */
public class Dat_04_2 {
    private static HashMap<Integer, Integer> map = new HashMap<>();
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int k = input.nextInt();
        int m = input.nextInt();
        int[] nums = new int[11];
        // 接收n个数据
        for (int i = 1; i <= 10; i++) {
            nums[i] = input.nextInt();
        }
        System.out.println(solution(k,nums) % m);
    }

    private static int solution(int n, int[] nums) {
        if (n < 10) {
            return n;
        }
        int result = 0;
        for (int i = 1; i <= 10; i++) {
            result += nums[i] * getValue(n, i, nums);
        }
        return result;
    }

    private static int getValue(int n, int i,int[] nums) {
        Integer key = n;
        if (map.containsKey(key)) {
            return map.get(key);
        } else {
            int value = solution(n - i,nums);
            map.put(key,value);
            return value;
        }
    }
}
